<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="报关单号" prop="declarationNo">
        <el-input
          v-model="queryParams.declarationNo"
          placeholder="请输入报关单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预录入编号" prop="preEntryNo">
        <el-input
          v-model="queryParams.preEntryNo"
          placeholder="请输入预录入编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-plus"
          size="mini"
          :disabled="multiple"
          @click="handleBatchInvoice"
        >批量开票</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="pendingInvoiceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="报关单号" align="center" prop="declarationNo" />
      <el-table-column label="预录入编号" align="center" prop="preEntryNo" />
      <el-table-column label="报关类型" align="center" prop="declarationType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fiscale_declaration_type" :value="scope.row.declarationType"/>
        </template>
      </el-table-column>
      <el-table-column label="贸易方式" align="center" prop="tradeMode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fiscale_trade_mode" :value="scope.row.tradeMode"/>
        </template>
      </el-table-column>
      <el-table-column label="运输方式" align="center" prop="transportMode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fiscale_transport_mode" :value="scope.row.transportMode"/>
        </template>
      </el-table-column>
      <el-table-column label="出口日期" align="center" prop="exportDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.exportDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总金额" align="center" prop="totalAmount" />
      <el-table-column label="币种" align="center" prop="currency" />
      <el-table-column label="报关状态" align="center" prop="customsStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.fiscale_customs_status" :value="scope.row.customsStatus"/>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listPendingInvoices } from "@/api/fiscale/tax";

export default {
  name: "PendingInvoice",
  dicts: ['fiscale_declaration_type', 'fiscale_trade_mode', 'fiscale_transport_mode', 'fiscale_customs_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 待开票报关单表格数据
      pendingInvoiceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        declarationNo: null,
        preEntryNo: null,
        declarationType: null,
        tradeMode: null,
        transportMode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询待开票报关单列表 */
    getList() {
      this.loading = true;
      listPendingInvoices(this.queryParams).then(response => {
        this.pendingInvoiceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.declarationId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 批量开票按钮操作 */
    handleBatchInvoice() {
      const declarationIds = this.ids;
      this.$router.push({
        path: '/fiscale/tax/invoice-issue',
        query: { declarationIds: declarationIds.join(',') }
      });
    }
  }
};
</script>